package com.androidx.p013lv.base.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.androidx.p013lv.base.C1010R;
import com.androidx.p013lv.base.utils.LogUtils;

/* renamed from: com.androidx.lv.base.view.StatusControlLayout */
public class StatusControlLayout extends FrameLayout {
    public static final int SHOW_EMPTY = 4;
    public static final int SHOW_ERROR = 1;
    public static final int SHOW_LOADING = 2;
    public static final int SHOW_NORMAL = 0;
    public static final int SHOW_NO_NET = 3;
    private static final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -1);
    protected int contentViewId;
    public int currentStatus;
    protected TextView currentText;
    protected View currentView;
    private int emptyViewId;
    private int errorViewId;
    private LayoutInflater inflater;
    private int loadingViewId;
    private int noNetworkViewId;
    private View.OnClickListener onRetryListener;
    private SparseArray<View> views;

    public StatusControlLayout(Context context) {
        this(context, null);
    }

    public StatusControlLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public StatusControlLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.currentStatus = 0;
        this.views = new SparseArray<>();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C1010R.styleable.StatusControlLayout);
        this.contentViewId = obtainStyledAttributes.getResourceId(C1010R.styleable.StatusControlLayout_contentView, -1);
        this.emptyViewId = obtainStyledAttributes.getResourceId(C1010R.styleable.StatusControlLayout_emptyView, C1010R.C1015layout.base_control_layout_empty_view);
        this.errorViewId = obtainStyledAttributes.getResourceId(C1010R.styleable.StatusControlLayout_errorView, C1010R.C1015layout.base_control_layout_error_view);
        this.loadingViewId = obtainStyledAttributes.getResourceId(C1010R.styleable.StatusControlLayout_loadingView, C1010R.C1015layout.base_control_layout_loading_view);
        this.noNetworkViewId = obtainStyledAttributes.getResourceId(C1010R.styleable.StatusControlLayout_noNetworkView, C1010R.C1015layout.base_control_layout_no_network_view);
        this.inflater = LayoutInflater.from(context);
        obtainStyledAttributes.recycle();
    }

    public void setOnTouchListener(View.OnTouchListener onTouchListener) {
        LogUtils.m63e("点击", "OnTouchListener");
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        LogUtils.m63e("点击", "OnClickListener");
    }

    /* access modifiers changed from: protected */
    public void onFinishInflate() {
        super.onFinishInflate();
        if (this.contentViewId == -1) {
            getChildCount();
        }
    }

    public void showEmpty() {
        this.currentStatus = 4;
        showView(this.emptyViewId);
    }

    public void showError() {
        this.currentStatus = 1;
        showView(this.errorViewId);
    }

    public void showLoading() {
        this.currentStatus = 2;
        showView(this.loadingViewId);
    }

    public void showNoNet() {
        this.currentStatus = 3;
        showView(this.noNetworkViewId);
    }

    public void hideLoading() {
        this.currentStatus = 0;
        if (this.currentView != null && getChildCount() > 0) {
            removeAllViews();
        }
    }

    public void showStatusView(int i) {
        if (i == 1) {
            showError();
        } else if (i == 2) {
            showLoading();
        } else if (i == 3) {
            showNoNet();
        } else if (i != 4) {
            hideLoading();
        } else {
            showEmpty();
        }
    }

    public void showView(int i) {
        View ViewFactory = ViewFactory(i);
        this.currentView = ViewFactory;
        if (ViewFactory == null) {
            Log.e("StatusControlLayout", "getView = null");
            return;
        }
        if (getChildCount() > 0) {
            removeAllViews();
        }
        View view = this.currentView;
        if (!(view == null || this.onRetryListener == null || i == this.loadingViewId)) {
            View findViewById = view.findViewById(C1010R.C1013id.retry_view);
            this.currentText = (TextView) this.currentView.findViewById(C1010R.C1013id.tv_content);
            if (findViewById != null) {
                findViewById.setOnClickListener(this.onRetryListener);
            }
        }
        addView(this.currentView, params);
    }

    public void setText(String str) {
        TextView textView = this.currentText;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setOnRetryListener(View.OnClickListener onClickListener) {
        this.onRetryListener = onClickListener;
    }

    public View ViewFactory(int i) {
        View view = this.views.get(i);
        if (view != null) {
            return view;
        }
        View inflate = this.inflater.inflate(i, (ViewGroup) null);
        this.views.put(i, inflate);
        return inflate;
    }

    public int getCurrentStatus() {
        return this.currentStatus;
    }
}
